package com.liy.teaching.core.entity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

public class UserEntity implements UserDetails {

    private String username;

    private String password;

    private List<UserGrantedAuthority> userGrantedAuthorityList;  // 权限集合

    public UserEntity() {}

    public UserEntity(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public UserEntity(String username, String password, List<UserGrantedAuthority> userGrantedAuthorityList) {
        this.username = username;
        this.password = password;
        this.userGrantedAuthorityList = userGrantedAuthorityList;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return userGrantedAuthorityList;
    }

    // 设置权限
    public List<UserGrantedAuthority> getUserGrantedAuthorityList() {
        return userGrantedAuthorityList;
    }

    // 设置权限
    public void setUserGrantedAuthorityList(List<UserGrantedAuthority> userGrantedAuthorityList) {
        this.userGrantedAuthorityList = userGrantedAuthorityList;
    }


    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
